﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;

namespace VntNet.PowerSchemeSwitcher
{
    static class Program
    {
        static Mutex onlyOneAppMutex;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            bool ok;
            string mutexName=String.Format("{0}-{1}-{2}-SingleInstance",Application.CompanyName,Application.ProductName,Application.ProductVersion);
            onlyOneAppMutex = new Mutex(true, mutexName, out ok);
            //TODO: Error Icon here
            if (!ok)
            {
                MessageBox.Show("Another instance is already running.");
                return;
            }

            if (!IsValidOs())
                throw new InvalidOperationException(string.Format("This application does not run on {0}. Works on Vista and latter",Environment.OSVersion.VersionString));

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new AppContext());
        }
        
        private static bool IsValidOs()
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
                return false;
            //works only on Vista (6) and greater(win7 6.1) 
            if (Environment.OSVersion.Version.Major < 6)
                return false;
            return true;
        }
    }
}
